﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xrm.Sdk;
using XRM.Solutions.FrameworkSample.Common.Entities;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using XRM.Framework.Test.Integration;

namespace XRM.Solution.FrameworkSample.IntegrationTests.Plugins
{
    [TestClass]
    public class TestPreAccountCreate : PluginIntegrationTest
    {
        #region Instance Variables

        private Guid accountId;
        private string accountNumber;

        #endregion

        #region Test

        [TestMethod]
        public void TestGenerateAccountNumber()
        {
            base.Test();
        }

        #endregion

        protected override void Setup()
        {
            accountNumber = "12345678";
            accountId = Guid.NewGuid();
        }

        protected override OrganizationRequest SetupTriggerRequest()
        {
            Account account = new Account();
            account.Name = "Test Account";
            account.AccountNumber = accountNumber;
            account.Id = accountId;
            return new CreateRequest() { Target = account };
        }

        protected override void Verify()
        {
            Account account = OrganizationService.Retrieve("account", accountId,
                new ColumnSet("accountnumber")).ToEntity<Account>();

            Assert.AreEqual(accountNumber, account.AccountNumber);
        }
    }
}
